package com.bosicen.crm.dao.sysmanage;

import java.util.List;


import org.springframework.stereotype.Component;
import com.bosicen.crm.dao.HibernateDao;
import com.bosicen.crm.dao.entity.User;
/****
 * 用户信息
 * @author Administrator
 *
 */
@Component("userDao")
@SuppressWarnings("unchecked")
public class UserDao extends HibernateDao<User, Integer> {

	/****
	 * 查询列表
	 * @param id
	 * @return
	 */
	
	public List<User> findUserList(int companyid){
		return this.getSession().createQuery(" from User where companyid=?  order by id asc").setParameter(0, companyid).list();
	}
	
	/**
	 * 查询单个用户
	 * @param id
	 * @return
	 */
	public User findUserById(int id){
		//return (User) this.getSession().get(User.class, id);
		return this.get(id);
	}
	
	/***
	 * 删除
	 * @param c
	 */
	public void delUser(User c){
		//this.getSession().createQuery("delete User where id=?").setParameter(0, c.getId()).executeUpdate();
		this.delete(c.getId());
	}
	
	/**
	 * 保存更新用户信息
	 */
	public void saveOrUpdate(User user){
		this.getSession().saveOrUpdate(user);
	}
	
	/****
	 * 登录信息查询
	 * @param u
	 * @return
	 */
	public User findUserByLogin(User u){
		User user=null;
		try{
			user=(User) this.getSession().createQuery("from User u where u.username=:name and u.pwd=:pwd ").setParameter("name", u.getName()).setParameter("pwd", u.getPwd()).uniqueResult();

		}catch(Exception ex){
			ex.printStackTrace();
		}
		return user;
	}
}
